<template>
	<view class="user-wallet-ye-page">
		<view class="header-box">
			<image src="../../static/images/bg_2.png" mode="widthFix" class="bg-img"></image>
			<view class="text1">我的余额（元）</view>
			<view class="text2">
				<text class="text">{{myWallet.user_money}}</text>
				<view class="btn" @tap="toUse">去使用</view>
			</view>
		</view>
		<view class="main-box">
			<view class="tab-box">
				<view v-for="v in tabList" :key="v.id" class="tab" :class="{'is-active':v.id==currTab.id}"
					@tap="changeTab(v)">{{v.name}}</view>
			</view>

			<view class="list-box">
				<view class="item" v-for="(item,i) in dataList" :key="i">
					<view class="top-bar">
						<view class="label">{{item.source_type_text}}</view>
						<view class="value">{{item.change_type_text}}{{item.change_amount}}</view>
					</view>
					<view class="footer-bar">
						<view class="date">{{item.create_time}}</view>
						<!-- <view class="type">租期：永久</view> -->
					</view>
				</view>
				<loading-footer :status="status"></loading-footer>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getYuEGoldList,
		getWallet
	} from '../../../api/user';
	import {
		loadingFun
	} from '../../../utils/tools';
	import {
		loadingType
	} from '../../../utils/type';
	const tabList = [{
		id: 1,
		name: '收益记录'
	}, {
		id: 2,
		name: '消费记录'
	}];
	export default {
		data() {
			return {
				page: 1,
				status: loadingType.LOADING,
				dataList: [],
				tabList: tabList,
				currTab: tabList[0],
				myWallet: null,
			};
		},

		components: {},
		props: {},

		onLoad: function(options) {
			this.getDataList();

			// 获取钱包信息
			getWallet().then(res => {
				if (res.code != 1) return this.$toast({
					title: res.msg
				});
				this.myWallet = res.data;
			})
		},

		onReachBottom() {
			this.getDataList();
		},
		methods: {
			clear() {
				this.page = 1;
				this.status = loadingType.LOADING;
				this.dataList = []
			},
			changeTab(v) {
				this.currTab = v;
				this.clear();
				this.getDataList();
			},
			async getDataList() {
				const data = await loadingFun(getYuEGoldList, this.page, this.dataList, this.status, {
					type: this.currTab.id
				});
				if (data) {
					this.page = data.page;
					this.dataList = data.dataList;
					this.status = data.status;
				}
			},
			toUse() {
				uni.switchTab({
					url: '/pages/lease/lease'
				})
			}
		}
	};
</script>
<style lang="scss" scoped>
	@import "index.scss";
</style>